#include<unistd.h>
#include<iostream>
using namespace std;

class Task
{
public:
  Task(){} //默认构造函数
  Task(int s) : sock(s)
  {}
  void Run() //和多进程/多线程服务当中的ServiceIO函数一致
  {
    while(1)
    {
        //1.读取客户端发来的请求
        char buf[1024] = {0}; 
        ssize_t s = read(sock,buf,sizeof(buf)-1);
        if(s > 0)
        {
          buf[s] = 0;
          std::string echo = ">>>>>server<<<<";
          echo += buf;
          cout << "client# " << buf << endl;

          write(sock,echo.c_str(),echo.size());
        }
        else if(s == 0)
        {
          cout << "client quit...."<< endl;
          break;
        }
        else 
        {
          cerr << "read err" << endl;
          break;
        }

    }
  }
private:
  int sock; //为哪个客户端提供服务的套接字 
};
